package com.eddie.hhcook.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.eddie.hhcook.R;


public class SharePopwindow extends PopupWindow implements OnClickListener{
    private Context context;

    public SharePopwindow(Context context) {
        super();
        this.context = context;
        initView();
    }

    private void initView() {
        View view = View.inflate(context, R.layout.share_popwindow, null);
        view.findViewById(R.id.iv_wx_share).setOnClickListener(this);
        view.findViewById(R.id.iv_wx_friends_share).setOnClickListener(this);
        view.findViewById(R.id.iv_sina_share).setOnClickListener(this);
        view.findViewById(R.id.tv_cancel).setOnClickListener(this);
        view.findViewById(R.id.view_click_region).setOnClickListener(this);

        setContentView(view);
        // 设置宽度
        setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        // 设置高度
        setHeight((int) context.getResources().getDimension(R.dimen.share_height));
        // 设置背景透明
        setBackgroundDrawable(new ColorDrawable(0));

        setOutsideTouchable(true);

        setAnimationStyle(R.style.AnimTools);

        getBackground().setAlpha(140);

    }

    public void showHints() {
        this.getContentView().findViewById(R.id.tv_hints).setVisibility(View.VISIBLE);
    }

    @Override
    public void onClick(View v) {
        if (null == onSharePopClickListener)
            return;
        try {
            switch (v.getId()) {
                case R.id.iv_wx_share:
                    onSharePopClickListener.click(1);
//                this.dismiss();
                    break;
                case R.id.iv_wx_friends_share:
                    onSharePopClickListener.click(2);
//                this.dismiss();
                    break;
                case R.id.iv_sina_share:
                    onSharePopClickListener.click(3);
//                this.dismiss();
                    break;
                case R.id.tv_cancel:
                    this.dismiss();
                    break;

                case R.id.view_click_region:
                    onRegionClickListener.click();
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private OnSharePopClickListener onSharePopClickListener;

    private OnRegionClickListener onRegionClickListener;

    public interface OnRegionClickListener {
        void click();
    }

    public OnRegionClickListener getOnRegionClickListener() {
        return onRegionClickListener;
    }

    public void setOnRegionClickListener(OnRegionClickListener onRegionClickListener) {
        this.onRegionClickListener = onRegionClickListener;
    }

    public void setOnSharePopClickListener(
            OnSharePopClickListener onSharePopClickListener) {
        this.onSharePopClickListener = onSharePopClickListener;
    }

    public interface OnSharePopClickListener {
        // type = 1 微信 2 朋友圈 3 新浪微博
        void click(int type);
    }
}
